﻿Public Class HelpWindow
    Inherits Window

    Private processor As CommandProcessor
    Private WithEvents helpList As ListWindow
    Private infoWindow As Window

    Public Sub New(commandProcessor As CommandProcessor)
        BackColor = ConsoleColor.DarkBlue
        ForeColor = ConsoleColor.White
        FrameColor = ConsoleColor.Blue
        CanFocus = False
        processor = commandProcessor
        AppendText(Space(ClientBounds.Width \ 2 - 6) & "COMMAND HELP")
        helpList = New ListWindow(0, 2, 1, ClientBounds.Height)
        For Each keyword In processor.GetCommandKeywords
            helpList.Add(keyword.ToUpper, False)
        Next
        helpList.AutoSizeWindow()
        helpList.BackColor = ConsoleColor.DarkBlue
        helpList.ForeColor = ConsoleColor.White
        infoWindow = New Window(helpList.Bounds.Width - 1, 2, Bounds.Width - helpList.Bounds.Width + 1, ClientBounds.Height)
        infoWindow.CanFocus = False
        infoWindow.BackColor = ConsoleColor.DarkBlue
        Children.Add(infoWindow)
        Children.Add(helpList)
    End Sub

    Protected Overrides Sub OnHidden(e As EventArgs)
        infoWindow.Hide()
        MyBase.OnHidden(e)
    End Sub

    Protected Overrides Sub OnShown(e As EventArgs)
        infoWindow.Show()
        helpList.Show()
        MyBase.OnShown(e)
    End Sub

    Private Sub helpList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles helpList.SelectedIndexChanged
        infoWindow.ClearText()
        If helpList.SelectedIndex > -1 Then
            Dim command As String = helpList.Item(helpList.SelectedIndex)
            processor.ShowCommandHelp(infoWindow, command)
        End If
    End Sub

    Private Sub helpList_Hidden(sender As Object, e As EventArgs) Handles helpList.Hidden
        Hide()
    End Sub
End Class
